package com.cmj.controller;

import com.cmj.domain.ResponseResult;
import com.cmj.domain.entity.Comment;
import com.cmj.service.CommentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.cmj.domain.SystemConstants.Comment_Type_Article;
import static com.cmj.domain.SystemConstants.Comment_Type_Link;

/**
 * 这是注释
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论",description = "评论相关接口")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /***
     * 查看文章评论
     * @param articleId 文章id
     * @param pageNum 页数
     * @param pageSize 每页大小
     * @return 返回评论
     */
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId,Integer pageNum,Integer pageSize){
        return commentService.commentList(Comment_Type_Article,articleId,pageNum,pageSize);
    }

    /***
     * 查看友链评论
     * @param pageNum 页数
     * @param pageSize 每页大小
     * @return 返回评论
     */
    @GetMapping("/linkCommentList")
    public ResponseResult linkCommentList(Integer pageNum,Integer pageSize){
        return commentService.commentList(Comment_Type_Link,null,pageNum,pageSize);
    }

    /***
     * 添加评论
     * @param comment 评论信息
     *                {"articleId":1,"type":0,"rootId":-1,"toCommentId":-1,"toCommentUserId":-1,"content":"评论了文章"}
     * @return 操作结果
     */
    @PostMapping
    public ResponseResult addComment(@RequestBody Comment comment){
        return commentService.addComment(comment);
    }
}
